from quto_auto.util.loginfo import LogInfo


class BrowserOperationEx:

    def __init__(self,driver):
        self.driver=driver
        self.loginfo = LogInfo()

    # 切换框架
    def change_frame(self, frame_name):
        self.driver.switch_to.parent_frame()  # 返回上一层框架
        self.driver.switch_to.frame(frame_name)  # 切进框架

    #切换窗体
    def window_hand(self,title_name):
        try:
            for window_id in self.driver.window_handles: #获取所有窗体的句柄（ID)
                self.driver.switch_to.window(window_id) #通过句柄切换窗体
                if self.driver.title == title_name:
                    break
        except Exception as e:
            self.loginfo.set_message('error', e)